home *** CD-ROM | disk | FTP | other *** search
- package asp.wizard;
-
- import asp.netobjects.nfx.ui.AwtUtil;
- import asp.netobjects.nfx.ui.OrderedListModel;
- import com.sun.java.swing.BorderFactory;
- import com.sun.java.swing.DefaultListModel;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JLabel;
- import com.sun.java.swing.JList;
- import com.sun.java.swing.JPanel;
- import com.sun.java.swing.JScrollPane;
- import com.sun.java.swing.ListModel;
- import java.awt.Container;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.Insets;
- import java.awt.event.ActionListener;
- import java.awt.event.ComponentEvent;
- import java.awt.event.MouseEvent;
- import java.lang.reflect.Array;
- import java.util.Enumeration;
- import java.util.TooManyListenersException;
-
- public class ListToListPanel extends JPanel {
- private JLabel _lblLeftList = new JLabel();
- private JLabel _lblRightList = new JLabel();
- private JList _lstLeft = new JList();
- private JList _lstRight = new JList();
- private JButton _btnToLeft = new JButton("<");
- private JButton _btnToRight = new JButton(">");
- private JScrollPane _scpLeft = new JScrollPane();
- private JScrollPane _scpRight = new JScrollPane();
- private boolean _moveSrcItems = false;
- private JButton _btnAllToLeft = new JButton("<<");
- private JButton _btnAllToRight = new JButton(">>");
- private ListToListXferItemListener _xferItemListener;
-
- public ListToListPanel() {
- this.initModels();
- this.initLayout();
- this.initComponentListeners();
- }
-
- public ListToListPanel(OrderedListModel modelLeft, String titleLeft, OrderedListModel modelRight, String titleRight) {
- this._lblLeftList.setText(titleLeft);
- this._lblRightList.setText(titleRight);
- this._lstLeft.setModel(modelLeft);
- this._lstRight.setModel(modelRight);
- this.initLayout();
- this.initComponentListeners();
- }
-
- protected void initModels() {
- this._lstLeft.setModel(new OrderedListModel());
- this._lstRight.setModel(new OrderedListModel());
- }
-
- protected void initLayout() {
- GridBagLayout gbl = new GridBagLayout();
- GridBagConstraints gbc = new GridBagConstraints();
- ((Container)this).setLayout(gbl);
- gbc.fill = 2;
- AwtUtil.addComponent(this, this._lblLeftList, gbl, gbc, 0, 0, 1, 1, (double)0.0F, (double)0.0F);
- gbc.fill = 2;
- AwtUtil.addComponent(this, this._lblRightList, gbl, gbc, 2, 0, 1, 1, (double)1.0F, (double)0.0F);
- gbc.fill = 1;
- this._lstLeft.setFixedCellWidth(100);
- this._scpLeft.setBorder(BorderFactory.createLoweredBevelBorder());
- this._scpLeft.getViewport().setView(this._lstLeft);
- AwtUtil.addComponent(this, this._scpLeft, gbl, gbc, 0, 1, 1, 4, (double)0.0F, 0.3);
- gbc.fill = 2;
- gbc.anchor = 15;
- gbc.insets = new Insets(0, 3, 0, 3);
- AwtUtil.addComponent(this, this._btnToRight, gbl, gbc, 1, 1, 1, 1, (double)0.0F, 0.3);
- gbc.insets.bottom = 0;
- this._lstRight.setFixedCellWidth(100);
- gbc.fill = 1;
- gbc.anchor = 10;
- gbc.insets = new Insets(0, 0, 0, 0);
- this._scpRight.setBorder(BorderFactory.createLoweredBevelBorder());
- this._scpRight.getViewport().setView(this._lstRight);
- AwtUtil.addComponent(this, this._scpRight, gbl, gbc, 2, 1, 1, 4, (double)1.0F, 0.3);
- gbc.insets.top = 5;
- gbc.fill = 2;
- gbc.anchor = 10;
- gbc.insets = new Insets(5, 3, 0, 3);
- AwtUtil.addComponent(this, this._btnAllToRight, gbl, gbc, 1, 2, 1, 1, (double)0.0F, (double)0.0F);
- gbc.insets.top = 5;
- gbc.fill = 2;
- gbc.anchor = 11;
- gbc.insets = new Insets(5, 3, 0, 3);
- AwtUtil.addComponent(this, this._btnAllToLeft, gbl, gbc, 1, 3, 1, 1, (double)0.0F, (double)0.0F);
- gbc.insets.top = 5;
- gbc.fill = 2;
- gbc.anchor = 11;
- gbc.insets = new Insets(5, 3, 0, 3);
- AwtUtil.addComponent(this, this._btnToLeft, gbl, gbc, 1, 4, 1, 1, (double)0.0F, 0.3);
- }
-
- protected void initComponentListeners() {
- ActionListener l2lp = new L2LPActionListener(this);
- this._btnToLeft.addActionListener(l2lp);
- this._btnToRight.addActionListener(l2lp);
- this._btnAllToLeft.addActionListener(l2lp);
- this._btnAllToRight.addActionListener(l2lp);
- }
-
- public JLabel getLeftListLabel() {
- return this._lblLeftList;
- }
-
- public JLabel getRightListLabel() {
- return this._lblRightList;
- }
-
- public JList getLeftList() {
- return this._lstLeft;
- }
-
- public JList getRightList() {
- return this._lstRight;
- }
-
- public JButton getToRightButton() {
- return this._btnToRight;
- }
-
- public JButton getToLeftButton() {
- return this._btnToLeft;
- }
-
- protected void moveToRight(boolean all) {
- this.moveFromTo(this._lstLeft, this._lstRight, all);
- }
-
- protected void moveToLeft(boolean all) {
- this.moveFromTo(this._lstRight, this._lstLeft, all);
- }
-
- protected void copyToRight(boolean all) {
- this.copyFromTo(this._lstLeft, this._lstRight, all);
- }
-
- protected void removeFromRight(boolean all) {
- this.removeFrom(this._lstRight, all);
- }
-
- protected void setMoveSrcItems(boolean set) {
- this._moveSrcItems = set;
- }
-
- protected void moveFromTo(JList lstSrc, JList lstDst, boolean all) {
- int[] selIndices = null;
- if (all) {
- int numitems = lstSrc.getModel().getSize();
- selIndices = new int[numitems];
-
- for(int i = 0; i < numitems; selIndices[i] = i++) {
- }
- } else {
- selIndices = lstSrc.getSelectedIndices();
- }
-
- if (selIndices != null && Array.getLength(selIndices) >= 1) {
- DefaultListModel mdlSrc = (DefaultListModel)lstSrc.getModel();
- DefaultListModel mdlDst = (DefaultListModel)lstDst.getModel();
- int del = 0;
-
- for(int i = 0; i < Array.getLength(selIndices); ++i) {
- Object item = mdlSrc.getElementAt(selIndices[i] - del);
- if (this._xferItemListener != null) {
- item = this._xferItemListener.getItemToXfer(item);
- }
-
- if (item != null) {
- mdlSrc.removeElementAt(selIndices[i] - del);
- mdlDst.addElement(item);
- ++del;
- }
- }
-
- }
- }
-
- protected void copyFromTo(JList lstSrc, JList lstDst, boolean all) {
- int[] selIndices = null;
- if (all) {
- int numitems = lstSrc.getModel().getSize();
- selIndices = new int[numitems];
-
- for(int i = 0; i < numitems; selIndices[i] = i++) {
- }
- } else {
- selIndices = lstSrc.getSelectedIndices();
- }
-
- if (selIndices != null && Array.getLength(selIndices) >= 1) {
- OrderedListModel mdlSrc = (OrderedListModel)lstSrc.getModel();
- OrderedListModel mdlDst = (OrderedListModel)lstDst.getModel();
-
- for(int i = 0; i < Array.getLength(selIndices); ++i) {
- Object srcItem = ((DefaultListModel)mdlSrc).getElementAt(selIndices[i]);
- boolean found = false;
- Enumeration e = ((DefaultListModel)mdlDst).elements();
-
- while(e.hasMoreElements()) {
- Object dstItem = e.nextElement();
- if (dstItem == srcItem) {
- found = true;
- }
- }
-
- if (!found) {
- if (this._xferItemListener != null) {
- srcItem = this._xferItemListener.getItemToXfer(srcItem);
- }
-
- if (srcItem != null) {
- mdlDst.addElement(srcItem);
- }
- }
- }
-
- }
- }
-
- protected void removeFrom(JList lst, boolean all) {
- int[] selIndices = null;
- if (all) {
- int numitems = lst.getModel().getSize();
- selIndices = new int[numitems];
-
- for(int i = 0; i < numitems; selIndices[i] = i++) {
- }
- } else {
- selIndices = lst.getSelectedIndices();
- }
-
- if (selIndices != null && Array.getLength(selIndices) >= 1) {
- OrderedListModel mdl = (OrderedListModel)lst.getModel();
-
- for(int i = 0; i < Array.getLength(selIndices); ++i) {
- ((DefaultListModel)mdl).getElementAt(selIndices[i] - i);
- mdl.removeElementAt(selIndices[i] - i);
- }
-
- }
- }
-
- protected void handleListSelection(MouseEvent e) {
- if (((ComponentEvent)e).getComponent() == this._lstLeft) {
- this._btnToRight.setEnabled(true);
- } else if (((ComponentEvent)e).getComponent() == this._lstRight) {
- this._btnToLeft.setEnabled(true);
- }
-
- }
-
- public void addListToListXferItemListener(ListToListXferItemListener l) throws TooManyListenersException {
- if (this._xferItemListener != null) {
- throw new TooManyListenersException("ListToTablePanel can only have one listener");
- } else {
- this._xferItemListener = l;
- }
- }
-
- public void removeListToListXferItemListener(ListToListXferItemListener l) {
- this._xferItemListener = null;
- }
-
- public void setLeftListModel(ListModel listModel) {
- if (listModel != null) {
- this._lstLeft.setModel(listModel);
- this._lstLeft.invalidate();
- Container rootContainer = this._lstLeft.getTopLevelAncestor();
- if (rootContainer != null) {
- rootContainer.validate();
- }
-
- if (listModel.getSize() > 0) {
- this._lstLeft.setSelectedIndex(0);
- }
- }
-
- }
-
- // $FF: synthetic method
- static JButton access$0(ListToListPanel $0) {
- return $0._btnToLeft;
- }
-
- // $FF: synthetic method
- static JButton access$1(ListToListPanel $0) {
- return $0._btnAllToLeft;
- }
-
- // $FF: synthetic method
- static boolean access$2(ListToListPanel $0) {
- return $0._moveSrcItems;
- }
-
- // $FF: synthetic method
- static JButton access$3(ListToListPanel $0) {
- return $0._btnToRight;
- }
-
- // $FF: synthetic method
- static JButton access$4(ListToListPanel $0) {
- return $0._btnAllToRight;
- }
- }
-